package com.hy.study.sort;

import java.util.Arrays;

public class SelectSort {
    public static void main(String[] args) {
        int arr[] =new  int[80000];
        for (int i = 0; i < arr.length; i++) {
            arr[i]=(int)(Math.random()*800000);
        }
        System.out.println("----------排序前----------");

      //   System.out.println(Arrays.toString(arr));
        long startTime = System.currentTimeMillis();
        selectSort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println("----------排序后----------");


      //  System.out.println(Arrays.toString(arr));
        System.out.println("---------总共耗时("+(endTime-startTime)/1000+"秒)");

    }

    public static  void selectSort(int arr[]){
        for (int i = 0; i < arr.length-1; i++) {
            int min=arr[i];
            int minIndex=i;
            for (int j = i+1; j < arr.length; j++) {
                   if(arr[j]<min){
                       min=arr[j];
                       minIndex=j;
                   }
            }

            if(minIndex!=i){
                arr[minIndex]=arr[i];
                arr[i]=min;
            }

        }
    }
}
